package com.common.demo.util;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;


/**
 * @author 33117
 * @version 1.0
 * @data 2025/8/19 16:14
 * 统一返回结果
 */

public class VfResult<T> {
    // 定义jackson对象
    private static final ObjectMapper MAPPER = new ObjectMapper();

    // 响应业务状态
    private Integer status;


    // 响应消息
    private String msg;

    // 响应中的数据
    private T data;

    @JsonIgnore
    private String ok;	// 不使用

    public static <T> VfResult<T> build(Integer status, String msg, T data) {
        return new VfResult<>(status, msg, data);
    }

    public static <T> VfResult<T> build(Integer status, String msg, T data, String ok) {
        return new VfResult<>(status, msg, data, ok);
    }

    public static<T> VfResult<T> ok(T data) {
        return new VfResult<>(data);
    }

    public static <T> VfResult<T> ok() {
        return new VfResult<>(null);
    }

    public static <T> VfResult<T> errorMsg(String msg) {
        return new VfResult<>(500, msg, null);
    }
    public static <T> VfResult<T> errorMsg(int code , String msg) {
        return new VfResult<>(code, msg, null);
    }

    public static <T> VfResult<T> errorMap(T data) {
        return new VfResult<>(501, "error", data);
    }

    public static <T> VfResult<T> errorTokenMsg(String msg) {
        return new VfResult<>(502, msg, null);
    }

    public static <T> VfResult<T> errorException(String msg) {
        return new VfResult<>(555, msg, null);
    }

    public static <T> VfResult<T> errorUserQQ(String msg) {
        return new VfResult<>(556, msg, null);
    }

    public VfResult() {

    }

    public VfResult(int value, String s) {
        this.status = value;
        this.msg = s;
    }

    public VfResult(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public VfResult(Integer status, String msg, T data, String ok) {
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.ok = ok;
    }

    public VfResult(T data) {
        this.status = 200;
        this.msg = "OK";
        this.data = data;
    }

    public Boolean isOK() {
        return this.status == 200;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getOk() {
        return ok;
    }

    public void setOk(String ok) {
        this.ok = ok;
    }

    public static ObjectMapper getMAPPER() {
        return MAPPER;
    }
}
